home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / term.zip / TERM.ASM < prev    next >
Assembly Source File  |  1988-02-07  |  34KB  |  1,327 lines

  1. ;
  2. ;   vi:set ts=8:
  3. ;
  4. TITLE   terminal program
  5. ;
  6. ;    This is version 2.2 of TERM. TERM is a terminal program that
  7. ;    emulates a zenith z19 terminal. It's main feature is, that it is
  8. ;    memory-resident. This allows you to run two tasks simultaneouly,
  9. ;    one on your dos machine, the other on the host computer.
  10. ;    You can switch easily back and forth by pressing the hotkey.
  11. ;    TERM has a 2048 character receive buffer, and receives characters 
  12. ;    while you are doing other things under Dos. The characters are
  13. ;    printed on the screen, when you switch back to the host.
  14. ;    When term receives the bell character, while it's in the
  15. ;    background, it will switch immediately to the foreground.
  16. ;    Thus, you are notified if you receive mail (biff) or
  17. ;    someone wants to talk with you
  18. ;
  19. ;      Mail problems, suggestions or bug reports to:
  20. ;
  21. ;          Karl Gegenfurtner
  22. ;
  23. ;arpa:     karl@hipl.psych.nyu.edu
  24. ;uucp      {ihnp4|seismo|allegra}!cmcl2!xp!hipl!karl
  25. ;usps:     New York University
  26. ;          Dept. of Psychology
  27. ;          6 Washington Place 8th floor
  28. ;          New York, NY 10003
  29. ;
  30. ;    In the case, that you make major improvements to term,
  31. ;    like adding file transfer capabilities, I really would
  32. ;    want to get copy of the program, before you sell it.
  33. ;    
  34. ;    History:
  35. ;    - fall 1986: Version 1.0 by Hans Irtel, Uni Regensburg
  36. ;             output is via ansi driver int 29h
  37. ;             send xoff/xon when switching
  38. ;    - spring 87: Version 2.0 by Karl Gegenfurtner, New York University
  39. ;             added z19 emulation
  40. ;             rewrote the comm-initialization routines
  41. ;             made the dos interface well-behaved
  42. ;             put xon/xoff into interrupt routine
  43. ;    - april  87: Version 2.1 Wed Apr 01 18:35:05 1987
  44. ;             added alarm feature
  45. ;              added support for monochrome card
  46. ;    - april  87: Version 2.2 Thu Apr 02 19:12:39 1987
  47. ;             dynamically allocate rxbuffer to reduce prog size
  48. ;             fix cexit bug (restore comm int)
  49. ;             fix the monochrome cursor
  50. ;             add keypad enter pseudo sequences for xp
  51. ;             moved cinit and cexit to non-resident part
  52. ;             made some equates to variables for install
  53. ;             fix the silly bug in kb_int, which caused two
  54. ;            instances of term running simultaneously
  55. ;                Wed Apr 08 20:06:07 1987
  56. ;             fixed init code in enab
  57. ;             
  58. ;
  59. ;    Future:
  60. ;    - write installation program
  61. ;    - add some primitive functions for reinitializing etc.
  62. ;
  63. ;
  64. ;
  65. ;   installation equates
  66. ;
  67. Ifgcolor    equ        74h
  68. Ibgcolor    equ        47h
  69. Iswitchcode equ     3400h   ; 3400h is F12 on an AT
  70.                 ; 4400 is F10 on a PC
  71.                 ; 7000 is alt-f9 on a PC
  72. Itport        equ        2        ; comm port to use
  73. Iline_par   equ     11100011b
  74.                 ; comm line parameters
  75.                 ; 8 data bits, 1 stopbit, no parity
  76. logo        equ     "HI"    ; for Hans Irtel
  77. terminal_page equ   1       ; alternate video page
  78. show_ctrl   equ        0        ; show ctrl chars as ^x
  79. ;
  80. ;   other useful defines
  81. ;
  82. xon         equ     11h
  83. xoff        equ     13h
  84. eoi         equ     20h     ; non-specific eoi
  85. c1mask      equ     0efh
  86. c2mask      equ     0f7h
  87. c1off       equ     10h
  88. c2off       equ     08h
  89. c1base      equ     03f8h
  90. c2base      equ     02f8h
  91. c1int       equ     0ch
  92. c2int       equ     0bh
  93. int_enable  equ     1
  94. line_control    equ     3
  95. modem_control   equ     4
  96. line_status     equ     5
  97. buflen      equ     2048
  98. maxcount    equ     buflen-64
  99. lowcount    equ     128
  100.  
  101. chesc   equ     27
  102. bel     equ     7
  103. cr      equ     13
  104. lf      equ     10
  105. bs      equ     8
  106. tab     equ     9
  107.  
  108. screen  equ     10h                     ; bios screen call
  109. screensize equ  25*80
  110.  
  111. timer   equ     40h                     ; timer port
  112. bel_prt equ     61h                     ; speaker control
  113.  
  114. crt_status equ  3dah                    ; crt status port
  115. disp_enb   equ  8                       ; display enable bit
  116.  
  117. code_seg segment
  118.     assume cs:code_seg, ds:code_seg, es:code_seg
  119.  
  120.     org 100H
  121.  
  122. terminal proc far
  123.     jmp install
  124. terminal endp
  125.  
  126. ;
  127. ;   the first data may be changed by the installation program
  128. ;
  129. fgcolor     DB     Ifgcolor
  130. bgcolor     DB    Ibgcolor
  131. tport        DW  Itport
  132. line_par    DB  Iline_par
  133. switchcode  DW  Iswitchcode
  134. ;
  135. ;   data for routines
  136. ;
  137.  
  138. old_com1    DW  00H
  139. old_com2    DW  00H
  140. kb_bios     label dword
  141. old_kb1     DW  00H
  142. old_kb2     DW  00H
  143. rxbuffer    DW  offset lastbyte
  144. buf_end     DW  offset lastbyte + buflen
  145. head        DW  offset lastbyte
  146. tail        DW  offset lastbyte
  147. tflag       DB  0
  148. alarm        DB  0
  149. bw        DB  0
  150. count       DW  0
  151. txoff       DB  0
  152. rxoff       DB  0
  153. rxfull      DB  0
  154. cbase       DW  0
  155. cmask       DB  0
  156. coff        DB  0
  157. cint        DB  0
  158. freemem     DW  offset lastbyte + buflen
  159. usersave    DW  offset lastbyte + buflen + 2
  160. termsave    DW  offset lastbyte + buflen + 2 + screensize * 2
  161. mofreemem   DW  offset lastbyte + buflen + 2 + screensize * 2 * 2
  162. usercursor  DW  0
  163. termcursor  DW  0
  164.  
  165. ;
  166. ; stuff for screen routines
  167. ;
  168. trnctl  equ     80h
  169. lnwrap  equ     40h                     ; line wrap enabled.
  170. line25  equ     20h
  171. IF    show_ctrl
  172. flags   db    0C0h
  173. ELSE
  174. flags   db      40h                     ; status flags...
  175. ENDIF
  176. cursor  dw      0
  177. esc_ch  db      ?
  178. argadr  dw      ?                       ; address of arg blk
  179.  
  180. spctab  db      chesc, cr, lf, bs, tab, bel
  181. lspctab equ     $-spctab
  182. spcjmp  dw      outesc,outcr,outlf,outbs,outtab,outbel  ; must match spctab
  183. esctab  db      'YABCDEFGHIJKLM'
  184.     db      'NOZ@[pq<vw'
  185.     db      'jk'
  186.     db      'xy'
  187.     db    '>='
  188. lesctab equ     $-esctab
  189. ; escjmp must parallel esctab above
  190. escjmp  dw      movcur,curup,curdwn,currt,outbs,clrscr,outign,outign,curhom
  191.     dw      revind,clreow,clreol,inslin,dellin,delchr,noins
  192.     dw      vtident,entins,doansi
  193.     dw      invvid,nrmvid,outign,dowrap,nowrap
  194.     dw      savecur,restcur
  195.     dw      smarg, rmarg
  196.     dw    escign, escign
  197. coord   dw      ?
  198. insmod  db      ?
  199. wcoord  dw      ?
  200. ttstate dw      offset scrini
  201. curattr db      ?                       ; current attribute
  202. ansarg  db      ?                       ; ansi argument value
  203. igncnt  db      ?                       ; # of chars to ignore
  204. beldiv  dw      2dch                    ; 550 hz?
  205. crt_mode db     ?
  206. crt_cols db     80
  207. crt_lins db     24      
  208. crt_page db     0
  209. low_rgt dw      ?                       ; lower right corner of window
  210. oldcur  dw      0                       ; save'd cursor position
  211.  
  212. ;---------------------------------------------------------------------
  213. ;   communication interface routines:
  214. ;    cinit:     initialize interrupts of port in dx
  215. ;    cgetch:    get next charcacter from buffer to al
  216. ;    cputch:    put character in al out on comm port
  217. ;    cexit:    reset interrupts
  218. ;    rxchar: interrupt service routine
  219. ;----------------------------------------------------------------------
  220. ;
  221. ;   interface routines
  222. ;
  223. ;    cinit moved to non-resident part
  224. ;
  225. ;  second entry point just for a re-init
  226. ;
  227. enab    proc near
  228. ;
  229. ;   set up the serial card
  230. ;
  231.     mov dx, cbase
  232.     add dx, line_control
  233.     mov al, 3
  234.     out dx, al
  235.     mov dl, 0f8h
  236.     in al, dx
  237. ;
  238. ;   start RS232 interrupt
  239. ;
  240.     mov dx, cbase
  241.     add dx, int_enable
  242.     mov al, 1
  243.     out dx, al
  244.     mov dl, 0fch
  245.     mov al, 0fh
  246.     out dx, al
  247. ;
  248. ;   set up 8259 interrupt controller
  249. ;
  250.     cli
  251.     in al, 21H
  252.     and al, cmask
  253.     out 21H, al
  254.     sti
  255. ;
  256. ;   done
  257. ;
  258.     ret
  259. enab    endp
  260.  
  261. ;
  262. ;   cexit moved to the non-resident part
  263. ;
  264.  
  265. cgetch  proc    near
  266.     cmp count, 0
  267.     je  gc3
  268.     mov bx, head
  269.     mov al, [bx]
  270.     inc bx
  271.     cmp bx, buf_end
  272.     jne gc1
  273.     mov bx, rxbuffer
  274. gc1:    mov head, bx
  275.     cli                     ; no interrupts during change of count
  276.     dec count
  277.     sti
  278. ;
  279. ; check for leaving buffer full state
  280. ;
  281.     test rxfull, 80h
  282.     jz gc2
  283. ;
  284. ; we are in rxfull state
  285. ;
  286.     cmp count, lowcount
  287.     ja gc2
  288. ;
  289. ; buffer is free to receive new charcters now
  290. ;
  291.     push ax
  292.     mov ax, xon                 ; send XON protocol
  293.     call txchar
  294.     mov rxfull, 0
  295.     mov rxoff, 0
  296.     pop ax
  297. gc2:    mov ah, 0
  298.     ret
  299. gc3:    mov ax, -1
  300.     ret
  301. cgetch endp
  302.  
  303. cputch  proc    near
  304.     test txoff, 80h
  305.     jnz t0
  306.     call txchar         ; character in al
  307.     jmp t1
  308. ;
  309. ;   in txoff state: return without sending
  310. ;
  311. t0:     mov ax, -1
  312. t1: